<template>
  <div class="lmain">
    <h1 style="margin-top: 60%">访客登记系统</h1>
    <div style="margin-top: 40px">
      <van-form ref="zform" @submit="onSubmit">
        <van-cell-group inset>
          <van-field
            v-model="form.username"
            name="username"
            label="用户名"
            placeholder="请填写用户名"
            :rules="[{ required: true, message: '请填写用户名' }]"
          />
          <van-field
            v-model="form.password"
            type="password"
            name="password"
            label="密码"
            placeholder="请填写密码"
            :rules="[{ required: true, message: '请填写密码' }]"
          />
        </van-cell-group>
        <div style="margin: 16px">
          <van-button round block type="primary" native-type="submit">
            登录
          </van-button>
        </div>
      </van-form>
    </div>
  </div>
</template>

<script setup lang="ts">
import { ref, getCurrentInstance } from "vue";
import { useUserStore } from "@/store/useUserStore";
import { showNotify } from "vant";
import { useRouter } from "vue-router";
// import logo from "../assets/images/mmexport1706252434740.png";

const router = useRouter();
const userStore = useUserStore();
const { Rlogin } = userStore;
const { proxy } = getCurrentInstance() as any;

const form = ref<any>({
  username: 17516211205,
  password: 600660,
});
const onSubmit = () => {
  proxy.$refs.zform
    .validate()
    .then(() => {
      Rlogin(form.value)
        .then((res: any) => {
          if (res.code == 200) {
            showNotify({ type: "success", message: res.msg });
            router.push("/qr");
          }
        })
        .catch((err) => {
          console.log(err);
          showNotify({ type: "warning", message: err });
        });
    })
    .catch((err: any) => {
      console.log(err);
      showNotify({ type: "warning", message: err });
    });
};
</script>

<style lang="scss" scoped>
.lmain {
  width: 100vw;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  align-items: center;
}
</style>
